package com.lushuai.jiubeidanci.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.lushuai.jiubeidanci.R;
import com.lushuai.jiubeidanci.model.WordMeaning;

import java.util.List;

public class WordMeaningAdapter extends RecyclerView.Adapter<WordMeaningAdapter.ViewHolder> {
    private List<WordMeaning> meanings;

    public WordMeaningAdapter(List<WordMeaning> meanings) {
        this.meanings = meanings;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_word_meaning, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        WordMeaning meaning = meanings.get(position);
        holder.tvType.setText(meaning.getType());
        holder.tvMeaning.setText(meaning.getMeaning());
    }

    @Override
    public int getItemCount() {
        return meanings.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvType;
        TextView tvMeaning;

        ViewHolder(View itemView) {
            super(itemView);
            tvType = itemView.findViewById(R.id.tv_type);
            tvMeaning = itemView.findViewById(R.id.tv_meaning);
        }
    }
} 